#include<iostream>
#include<string>
using namespace std;
class Apple
{
public:
    string id;
    int basketid;
    int weight=0;
    int diameter=0;
    Apple()
    {

    }
    Apple(int _basketid, string _id, int _weight, int _diameter)
    {
        basketid = _basketid;
        id = _id;
        weight = _weight;
        diameter = _diameter;
    }
    void Show()
    {
        cout << id << " " << weight << " " << diameter << endl;
    }
};
int main()
{
    int n;
    cin >> n;
    Apple* p = new Apple[n];
    for (int i = 0; i < n; i++)
    {
        int a;
        string b;
        int c;
        int d;
        cin >> a >> b >> c >> d;
        p[i] = Apple(a,b,c,d);
    }
    for (int i = 1; i <= 999999; i++)
    {
        Apple num;
        num.weight = 0;
        for (int j = 0; j < n; j++)
        {
                if ((p[j].basketid == i) && (p[j].weight > num.weight))
                    num = p[j];
        }
        if (num.weight > 0)
        {
            cout << i << " ";
            num.Show();
        }
    }
    delete[] p;
}